package org.pentaho.di.template;

import org.apache.commons.lang.StringUtils;

import java.util.Optional;

public class StringExtUtils {

    public static String javaName(String str, String splitStr) {
        String[] strArr = StringUtils.split(str, splitStr);
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < strArr.length; i++) {
            if (i == 0) {
                sb.append(strArr[i]);
            } else {
                sb.append(StringUtils.capitalize(strArr[i]));
            }
        }
        return sb.toString();
    }

    public static String javaName(String str, String splitStr, String wipeStr) {
        return Optional.ofNullable(str)
                .map(s1 -> StringUtils.replace(s1, wipeStr, ""))
                .map(s2 -> javaName(s2, splitStr))
                .orElse("");
    }

    public static String className(String str, String splitStr) {
        return Optional.ofNullable(str)
                .map(s1 -> javaName(s1, splitStr))
                .map(StringUtils::capitalize)
                .orElse("");
    }

    public static String className(String str, String splitStr, String wipeStr) {
        return Optional.ofNullable(str)
                .map(s1 -> javaName(s1, splitStr, wipeStr))
                .map(StringUtils::capitalize)
                .orElse("");
    }
}
